package com.gmom.tako.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class RSSSQLiteOpenHelper extends SQLiteOpenHelper {

	private static final String DB_NAME = "RSS_DATABASE";
	private static final int DATABASE_VERSION = 2;

	public static final String TABLE_ARTICLE = "article";
	public static final String TABLE_URL = "url";

	public static final String INSERT_ARTICLE = "INSERT INTO " + TABLE_ARTICLE
			+ "(url_id, title, detail, date, uid, link)values(?,?,?,?,?,?);";
	public static final String INSERT_URL = "INSERT INTO " + TABLE_URL
			+ "(title, url)values(?,?);";

	private static final String CREATE_TABLE_ARTICLE = "CREATE TABLE IF NOT EXISTS article "
			+ "( _id INTEGER  PRIMARY KEY AUTOINCREMENT, "
			+ "url_id INTEGER, "
			+ "title TEXT, "
			+ "detail TEXT, "
			+ "uid INTEGER, "
			+ "link TEXT,"
			+ "date TEXT);";

	private static final String CREATE_TABLE_URL = "CREATE TABLE IF NOT EXISTS url "
			+ "( _id INTEGER  PRIMARY KEY AUTOINCREMENT, "
			+ "title TEXT, "
			+ "url TEXT);";

	// DATABASEを作成するよ
	public RSSSQLiteOpenHelper(Context context) {
		super(context, DB_NAME, null, DATABASE_VERSION);
	}

	// テーブルを作成するよ
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_TABLE_ARTICLE);
		db.execSQL(CREATE_TABLE_URL);
		db.execSQL("INSERT INTO url(title,url)values('oesf rss ','http://www.oesf.jp/modules/news/index.php?page=rss')");
		db.execSQL("INSERT INTO url(title,url)values('geso','http://gesoten.com/rss/news')");
	}

	// テーブルを作り直すよ
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ARTICLE);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_URL);
		onCreate(db);
	}

}
